<template>
    <view class="content">
        <image src="../../static/image/s_img_11.jpg" class="s-img-11"></image>
        <u-navbar :background="background" title="我的余额" title-color="#000" :border-bottom="false" :immersive="true"
            :is-back="true" back-icon-color="#000"></u-navbar>
            
        <view class="wrapper" :style="{marginTop: statusBar + 50 + 'px'}">
            <view class="top">
                <view class="u-flex">
                    <image v-if="data.image" :src="data.image" class="avatar"></image>
                    <image v-else :src="IMAGEURL + 'static/icon/avatar.png'" class="avatar"></image>
                    <view class="name">{{data.name}}</view>
                </view>
                <view class="info-down">
                    <view>
                        <view>当前余额</view>
                        <view class="price">￥<text class="price-num">{{data.balance}}</text></view>
                    </view>
                    <view class="y-btn" @click="$gTo(`/serve/pages/balance/balance-list`)">余额变更记录</view>
                </view>
            </view>
            
            <view>
                <view class="title">
                    <view>提现金额</view>
                </view>
                <input type="digit" v-model="money" placeholder="请输入金额" class="t-inp">
            </view>
            
            <view class="down-box">
                <view class="title">
                    <view>提现金额</view>
                    <view class="card">
                        <image src="../../static/icon/card.png" class="card-icon"></image>
                        <view>银行卡</view>
                    </view>
                </view>
                <view class="box">
                    <view class="item">
                        <image src="../../static/icon/s_icon_08.png" class="s-icon-08"></image>
                        <input type="text" v-model="bank" placeholder="开户行名称" placeholder-class="p-inp" class="inp">
                    </view>
                    <view class="item">
                        <image src="../../static/icon/s_icon_09.png" class="s-icon-08"></image>
                        <input type="text" v-model="name" placeholder="开户姓名" placeholder-class="p-inp" class="inp">
                    </view>
                    <view class="item">
                        <image src="../../static/icon/s_icon_10.png" class="s-icon-08"></image>
                        <input type="text" v-model="card" placeholder="银行卡号" placeholder-class="p-inp" class="inp">
                    </view>
                    <view class="item">
                        <image src="../../static/icon/s_icon_11.png" class="s-icon-08"></image>
                        <input type="number" v-model="tel" placeholder="手机号" placeholder-class="p-inp" class="inp">
                    </view>
                </view>
                
                <view class="btn" @click="submit">确认提现</view>
            </view>
        </view>
    </view>
</template>

<script>
    import { IMAGEURL } from '@/static/js/common.js';
    export default {
        data() {
            return {
                IMAGEURL,
                statusBar: 0,
                background: { backgroundColor: 'rgba(255,255,255,0)' },
                data: {},
                money: '',//金额
                bank: '',//开户行名称
                name: '',//开户姓名
                card: '',//银行卡号
                tel: '',//手机号
            };
        },
        onLoad() {
            let _this = this;
            //状态栏高度
            uni.getSystemInfo({
            	success: function(res) {
            		_this.statusBar = res.statusBarHeight;
            	}
            });
            
            this.getData()
        },
        methods: {
            submit() {
                if (!this.money) {
                    this.$toast('请输入提现金额')
                    return
                }
                if (this.money < 1) {
                    this.$toast('提现金额不能小于1元')
                    return
                }
                if (this.money > this.data.balance) {
                    this.$toast('提现金额不能大于当前余额')
                    return
                }
                if (!this.bank) {
                    this.$toast('请输入开户行名称')
                    return
                }
                if (!this.name) {
                    this.$toast('请输入开户姓名')
                    return
                }
                if (!this.card) {
                    this.$toast('请输入银行卡号')
                    return
                }
                if (!this.tel) {
                    this.$toast('请输入手机号')
                    return
                }
                if (!this.$checkPhone(this.tel)) {
                    this.$toast('手机号码格式不正确');
                    return
                }
                this.$ajax('withdrawal', {
                	user_token: this.$getSync('userToken'),
                    balance: this.money,//金额
                    bank: this.bank,//开户行
                    bank_name: this.name,//开户人
                    bank_card: this.card,//银行卡号
                    bank_phone: this.tel,//开户手机号
                }).then(ret => {
                	if (ret.success == 1000) {
                		this.$toast('提交成功')
                        setTimeout(() => {
                            this.money = ''
                            this.getData()
                        }, 500)
                	} else {
                		this.$toast(ret.msg);
                	}
                });
            },
            
            // 获取我的余额
            getData() {
            	this.$ajax('users_balance', {
            		user_token: this.$getSync('userToken'),
            	}).then(ret => {
            		if (ret.success == 1000) {
            			this.data = ret.detail
                        if (ret.detail && ret.detail.bank) {
                            this.bank = ret.detail.bank
                            this.name = ret.detail.bank_name
                            this.card = ret.detail.bank_card
                            this.tel = ret.detail.bank_phone
                        }
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
            
            onPageScroll: function(e) {
            	//nvue暂不支持滚动监听，可用bindingx代替
            	// console.log("滚动距离为：" + e.scrollTop);
            	let a = e.scrollTop * 0.05;
            	if (a > 1) {
            		a = 1;
            	}
            	if (e.scrollTop == 0) {
            		this.background.backgroundColor = 'rgba(0,0,0,0)';
            	} else {
            		this.background.backgroundColor = 'rgba(255,255,255,' + a + ')';
            	}
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #fff;
    }
    .s-img-11{
        width: 750rpx;
        height: 562rpx;
        position: absolute;
        top: 0;
        left: 0;
        z-index: -1;
    }
    .wrapper{
        padding: 30rpx;
    }
    .top{
        padding: 50rpx;
        background: linear-gradient(to right, rgba(255,194,96,.7), rgba(239,151,2,.7));
        border-radius: 20rpx;
        margin-bottom: 100rpx;
    }
    .avatar{
        width: 85rpx;
        height: 85rpx;
        border: 2rpx solid #fff;
        border-radius: 50%;
        margin-right: 20rpx;
    }
    .name{
        flex: 1;
        font-size: 36rpx;
        color: #fff;
    }
    .info-down{
        padding-top: 30rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #fff;
        font-size: 24rpx;
    }
    .price{
        font-size: 34rpx;
    }
    .price-num{
        font-size: 56rpx;
    }
    .y-btn{
        line-height: 1;
        padding: 15rpx 17rpx;
        background-color: #20212c;
        border-radius: 50rpx;
    }
    
    
    .title{
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 32rpx;
        font-weight: bold;
        padding-bottom: 20rpx;
    }
    .card{
        font-size: 26rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .card-icon{
        width: 51rpx;
        height: 33rpx;
        margin-right: 10rpx;
    }
    .t-inp{
        width: 100%;
        height: 90rpx;
        padding: 0 25rpx;
        background-color: #f4f4f4;
        border-radius: 10rpx;
        margin-bottom: 30rpx;
    }
    .down-box{
        padding-top: 30rpx;
        border-top: 2rpx solid #e6e6e6;
    }
    .box{
        background-color: #f4f4f4;
        padding: 0 30rpx;
        border-radius: 15rpx;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30rpx 0;
        border-bottom: 2rpx solid #e7e5ed;
        font-size: 26rpx;
    }
    .item:last-child{
        border-bottom: none;
    }
    .s-icon-08{
        width: 33rpx;
        height: 33rpx;
        margin-right: 10rpx;
    }
    .inp{
        flex: 1;
    }
    .p-inp{
        color: #000;
    }
    .btn{
        font-size: 34rpx;
        color: #fff;
        text-align: center;
        padding: 25rpx;
        background-color: #f29700;
        border-radius: 10rpx;
        margin-top: 50rpx;
    }
    

</style>
